{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'paddlehub.datasets'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-11-e4437f4c6a65>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mpaddlehub\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdatasets\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbase_nlp_dataset\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mTextClassificationDataset\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[1;32mclass\u001b[0m \u001b[0mMyDataset\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mTextClassificationDataset\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m     \u001b[0mbase_path\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'/path/to/dataset'\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m     \u001b[0mlabel_list\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'体育'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'科技'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'社会'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'娱乐,股票'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'房产'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'教育'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'时政'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'财经'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'游戏'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'家居'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'彩票'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'时尚'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m__init__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mtokenizer\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mmax_seq_len\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0mint\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m128\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mmode\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'train'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'paddlehub.datasets'"
     ]
    }
   ],
   "source": [
    "from paddlehub.datasets.base_nlp_dataset import TextClassificationDataset\n",
    "class MyDataset(TextClassificationDataset):\n",
    "    base_path='/path/to/dataset'\n",
    "    label_list=['体育','科技','社会','娱乐,股票','房产','教育','时政','财经','游戏','家居','彩票','时尚']\n",
    "    def __init__(self,tokenizer,max_seq_len:int=128,mode:str='train'):\n",
    "        if mode == 'train':\n",
    "            data_file='train.txt'\n",
    "        elif mode == 'test':\n",
    "            data_file ='test.txt'\n",
    "        else:\n",
    "            data_file ='dev.txt'\n",
    "        super().__init__(\n",
    "            base_path=self.base_path,\n",
    "            tokenizer=tokenizer,\n",
    "            max_seq_len=max_seq_len,\n",
    "            mode=mode,\n",
    "            data_file=data_file,\n",
    "            label_list=self.label_list,\n",
    "            is_file_with_header=True)\n",
    "\n",
    "import paddlehub as hub\n",
    "model = hub.Module(name= 'ernie_tiny',task= 'seq-cls', num_classes=len(MyDataset.label_list))\n",
    "tokenizer = model.get_tokenizer()\n",
    "\n",
    "train_dataset=MyDataset(tokenizer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module 'paddlehub' has no attribute 'server_check'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-5-0bc82261d4ed>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mpaddlehub\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mpaddlehub\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mserver_check\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m: module 'paddlehub' has no attribute 'server_check'"
     ]
    }
   ],
   "source": [
    "import paddlehub\n",
    "paddlehub.server_check()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
